package com.andy.infrastructure.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileUtil {

    /**
     * 创建文件
     * @param fileName          XxxXxx.java
     * @param fileInfo
     * @param toFilePath        D:\\createVO
     * @throws IOException
     */
    public static void createFile(String fileName,String fileInfo,String toFilePath) throws IOException {
        File myPath = new File(toFilePath);
        if ( !myPath.exists()){
            myPath.mkdir();
            System.out.println("创建文件夹路径为："+ toFilePath);
        }
        File javafile =  new File(toFilePath+"\\"+fileName);
        FileOutputStream out = new FileOutputStream(javafile);
        out.write(fileInfo.getBytes());
        out.close();
    }

    /**
     * 弹出文件夹
     * @param toFilePath
     */
    public static void popupDir(String toFilePath){
        String[] cmd = new String[5];
        cmd[0] = "cmd";
        cmd[1] = "/c";
        cmd[2] = "start";
        cmd[3] = " ";
        cmd[4] = toFilePath;
        try {
            Runtime.getRuntime().exec(cmd);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
